﻿@model ShoppingCartVM
@{
    ViewBag.Title = "购物车";
}

<div class="container">
    <div class="container-fluid">
        <div class="row wizard">
            <div class="col-xs-4 active">
                购物车
            </div>
            <div class="col-xs-4">
                填写收件地址
            </div>
            <div class="col-xs-4">
                下单支付
            </div>
        </div>
    </div>
    <div class="panel panel-default">
        <div class="panel-heading">
          
            <h3 class="panel-title">
                购物车
            </h3>
        </div>
        <div class="panel-body">
           
            <div id="update-message">
            </div>
        </div>
       
        <table class="table table-hover table-vmiddle">
            <thead>
                <tr>
                    <th>
                        品名
                    </th>
                    <th>
                        价格
                    </th>
                    <th>
                        数量
                    </th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                @foreach (var item in Model.CartItems)
            {
                    <tr id="row-@item.Id">
                        <td>
                            @Html.ActionLink(item.Goods.Name,
"Details", "Store", new { id = item.GoodsId }, null)
                        </td>
                        <td>
                            @item.Goods.Price
                        </td>
                        <td id="item-count-@item.Id">
                            @item.Count
                        </td>
                        <td>
                            <a href="#" class="RemoveLink btn btn-default btn-sm"
                               data-id="@item.Id">
                                移除
                            </a>
                        </td>
                    </tr>
                }
            </tbody>
            <tfoot>
                <tr>
                    <td colspan="3" class="text-right">
                        合计
                    </td>                 
                    <td>
                        <strong id="cart-total">@Model.CartTotal</strong>
                       
                    </td>
                </tr>
            </tfoot>
        </table>
        <div class="panel-footer text-center">
            @Html.ActionLink("下一步", "SetAddress",null, new { @class = "btn btn-primary" })
        </div>
    </div>
   
   
    
</div>
@section footer{
    
    <script type="text/javascript">
    $(function () {
        // Document.ready -> link up remove event handler
        $(".RemoveLink").click(function () {
            // Get the id from the link
            var recordToDelete = $(this).attr("data-id");
            if (recordToDelete != '') {
                // Perform the ajax post
                $.post("/ShoppingCart/RemoveFromCart", {"id": recordToDelete },
                    function (data) {
                        // Successful requests get here
                        // Update the page elements
                        if (data.ItemCount == 0) {
                            $('#row-' + data.DeleteId).fadeOut('slow');
                        } else {
                            $('#item-count-' + data.DeleteId).text(data.ItemCount);
                        }
                        $('#cart-total').text(data.CartTotal);
                        $('#update-message').text(data.Message);
                        $('#cart-status').text('Cart (' + data.CartCount + ')');
                    });
            }
        });
    });
</script>
    }